package com.qingcheng.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.qingcheng.pojo.business.Ad;
import com.qingcheng.service.business.AdService;
import com.qingcheng.service.goods.CategoryService;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;

import java.util.List;
import java.util.Map;

@Controller  //因为使用的是springmvc框架，不用发送异步请求，因此不用RestController
public class ThymeleafController {
    @Reference
    private AdService adService;

    @Reference
    private CategoryService categoryService;

    /**
     * 定义获取首页广告的方法
     * @param model
     * @return
     */
    @GetMapping("/index")
    public String findName(Model model) {
        //获取主页轮播图
        List<Ad> adList = adService.getAdsFromRedis("web_index_lb");
        //将数据封装进map集合传入前端
        model.addAttribute("adList", adList);

        //获取主页的菜单
        List<Map> categoryList = categoryService.getCategoryFromRedis();
        model.addAttribute("categoryList",categoryList);
        return "index";
    }

}
